home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 072 (1988-11-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 072 (1988-11-15)(Ossowski, Stefan)(DE)(PD).adf / Surveyor / planeacc.a < prev    next >
Text File  |  1988-08-14  |  4KB  |  144 lines

  1.     nolist
  2.  
  3. *  Perhaps there is more implemented in asm than really necessary, but
  4. *  it does not harm either.
  5. *  Assem is the assembler I used. Lattice's asm is still too unfamiliar.
  6.  
  7.     include    "exec/types.i"
  8.     include    "exec/funcdef.i"
  9.     include    "exec/exec_lib.i"
  10.     include    "intuition/intuitionbase.i"
  11.     include    "intuition/screens.i"
  12.     include    "graphics/gfx.i"
  13.     list
  14.  
  15.     xdef    _GetDotColor,_SetDotColor
  16.     xref    _LVOLockIBase,_LVOUnlockIBase,_IntuitionBase
  17.  
  18.  
  19. *
  20. *  GetDotColor(x,y)
  21. *  ULONG x, y;
  22. *
  23. *  GetDotColor returns the color of a point in the BitMap of the 
  24. *  frontmost screen with the x and y coordinates.
  25. *  In case of error, -1 is returned.
  26. *
  27.     offset    5*4    d2/d3/d4/a6,return adress
  28. GDCx    ds.l    1
  29. GDCy    ds.l    1
  30.  
  31.     code
  32. _GetDotColor:
  33.     movem.l    d2/d3/d4/a6,-(a7)
  34.     move.l    _IntuitionBase,a6
  35.     moveq.l    #0,d0            Which one is the parameter?
  36.     sub.l    a0,a0            Donot change things while we are
  37.     jsr    _LVOLockIBase(a6)      looking at them.
  38.     move.l    d0,d4            lock_value
  39.     move.l    ib_FirstScreen(a6),a1
  40.     lea.l    sc_BitMap(a1),a1    Get structure
  41.     move.l    GDCx(a7),d2        Get X-coord
  42.     move.l    GDCy(a7),d3        Get Y-coord
  43.     bsr    GetOff            Calculate position in bitplane
  44.     bmi.s    GDCerr            X/Y not inside bitplane
  45.     moveq.l    #0,d1
  46.     move.b    bm_Depth(a1),d1        Number of bitplanes
  47.     lsl.l    #2,d1            Scale to longword
  48.     lea.l    bm_Planes(a1,d1),a1    Get adress of one past last plane
  49.     lsr.l    #2,d1            Back to number of bitplanes
  50.     moveq.l    #0,d0            Clear color collector
  51.     bra.s    10$            Start with plane-checking
  52. 20$    btst    d2,0(a0,d3.w)        Test X-Y bit in plane
  53.     beq.s    10$            Zero
  54.     bset    d1,d0            Set coordinating bit in color coll.
  55. 10$    move.l    -(a1),a0        Next plane (preceding)
  56.     subq.b    #1,d1            Check Depth
  57.     bpl.s    20$            Not done yet
  58. GDCerr  move.l    d0,d2            Keep returnvalue
  59.     move.l    d4,a0            lock_value
  60.     jsr    _LVOUnlockIBase(a6)    Things may change again
  61.     move.l    d2,d0
  62.     movem.l    (a7)+,d2/d3/d4/a6    Done, return color or error in d0
  63.     rts
  64.  
  65.  
  66. *
  67. *  SetDotColor(x,y,Color)
  68. *  short x, y, Color; 
  69. *
  70. *  SetDotColor sets the color of a point in the BitMap of the
  71. *  frontmost screen with the x and y coordinates.
  72. *  In case of error, -1 is returned.
  73. *
  74.     offset    5*4    d2/d3/d4/a6,return adress
  75. SDCx    ds.l    1
  76. SDCy    ds.l    1
  77. Color    ds.l    1
  78.  
  79.     code
  80. _SetDotColor:
  81.     movem.l    d2/d3/d4/a6,-(a7)
  82.     move.l    _IntuitionBase,a6
  83.     moveq.l    #0,d0            Which one is the parameter?
  84.     sub.l    a0,a0            Donot change things while we are
  85.     jsr    _LVOLockIBase(a6)      looking at them.
  86.     move.l    d0,d4            lock_value
  87.     move.l    ib_FirstScreen(a6),a1
  88.     lea.l    sc_BitMap(a1),a1    Get structure
  89.     move.l    SDCx(a7),d2        Get X-coord
  90.     move.l    SDCy(a7),d3        Get Y-coord
  91.     bsr.s    GetOff            Calculate position in bitplane
  92.     bmi.s    SDCerr            X/Y not inside bitplane
  93.     moveq.l    #0,d1
  94.     move.b    bm_Depth(a1),d1        Number of bitplanes
  95.     lsl.l    #2,d1            Scale to longword
  96.     lea.l    bm_Planes(a1,d1),a1    Get adress of one past last plane
  97.     lsr.l    #2,d1            Back to number of bitplanes
  98.     move.l    Color(a7),d0        Get color
  99.     bra.s    10$            Start with plane-checking
  100. 20$    btst    d1,d0            Check bit in color
  101.     beq.s    30$            Plane-bit must be cleared
  102.     bset.b    d2,0(a0,d3.w)        Set X-Y bit in plane
  103.     bra.s    10$
  104. 30$    bclr.b    d2,0(a0,d3.w)        Clear X-Y bit in plane
  105. 10$    move.l    -(a1),a0        Next plane (preceding)
  106.     subq.b    #1,d1            Check Depth
  107.     bpl.s    20$            Not done yet
  108.     moveq.l    #0,d0            No error
  109. SDCerr    move.l    d0,d2            Keep returnvalue
  110.     move.l    d4,a0            lock_value
  111.     jsr    _LVOUnlockIBase(a6)    Things may change again
  112.     move.l    d2,d0
  113.     movem.l    (a7)+,d2/d3/d4/a6    Done, return error in d0
  114.     rts
  115.  
  116.  
  117. *
  118. *  GetOff(BitMap,    X,    Y)
  119. *           a1.l, d2.l, d3.l
  120. *
  121. *  result: 
  122. *          d3.l  byte offset
  123. *          d2.l  bit  offset
  124. *
  125. *  error   CCR-N set, d0.l=-1
  126. *
  127.  
  128. GetOff
  129.     cmp.w    bm_Rows(a1),d3        Y out of range?
  130.     bpl.s    GOerr
  131.     mulu    bm_BytesPerRow(a1),d3    Scale Y
  132.     move.l    d2,d0            Get X, for byte offset
  133.     lsr.l    #3,d0            Was in dots, now in bytes
  134.     cmp.w    bm_BytesPerRow(a1),d0    X out of range?
  135.     bpl.s    GOerr
  136.     add.l    d0,d3            Add to scaled Y, bytes ok now
  137.     not.b    d2            68000 counts the other way around
  138.     and.w    #7,d2            Select bit count
  139.     rts
  140. GOerr    moveq.l    #-1,d0
  141.     rts
  142.  
  143.     end
  144.